public class test529_1 {
    public static void main(String[] args) {
        //二分法(要求数组是有序的)
        //long start = System.currentTimeMillis();
        int[] arr2 = {1,3,5,7,12,34,56,78,79,89,99,100,110,116,120};
        boolean isFlag = false;
        int target2 = 999,i = 0, head =  0, end = arr2.length-1, middle = (end + head) / 2;
        //利用二分法进行查找
        for (; head <= end; middle = (end + head) / 2) {
            if (target2 == arr2[middle]) {
                System.out.println("找到了:" + target2 + "，索引为：" + middle);
                isFlag = true;
                break;
            } else if (target2 > arr2[middle]) {
                head = middle + 1;
            } else {
                end = middle - 1;
            }
        }
        if (!isFlag) {
            System.out.println("不好意思，没有找到");
        }
        //long last = System.currentTimeMillis();
    }
}
